#include "division_engine/ffi/ffi.hpp"

#include "division_engine/canvas/border_radius.hpp"
#include "division_engine/canvas/components/render_bounds.hpp"
#include "division_engine/canvas/components/renderable_rect.hpp"
#include "division_engine/canvas/components/renderable_text.hpp"
#include "division_engine/canvas/rect.hpp"
#include "division_engine/canvas/rect_drawer.hpp"
#include "division_engine/canvas/render_manager.hpp"
#include "division_engine/canvas/state.hpp"
#include "division_engine/canvas/text_drawer.hpp"
#include "flecs/addons/cpp/entity.hpp"

#include <flecs.h>
#include <stdint.h>

using division_engine::canvas::BorderRadius;
using division_engine::canvas::Rect;
using division_engine::canvas::RenderManager;
using division_engine::canvas::State;
using division_engine::canvas::components::RenderableRect;
using division_engine::canvas::components::RenderableText;
using division_engine::canvas::components::RenderBounds;

using rect_renderable_t = division_engine::canvas::RectDrawer::renderable_type;
using text_renderable_t = division_engine::canvas::TextDrawer::renderable_type;

extern "C"
{
    uint64_t
    division_ffi_create_drawable_rect(State* state, RenderManager* render_manager)
    {
        return render_manager->create_renderer(
            *state, rect_renderable_t {}, state->white_texture_batch
        );
    }

    uint64_t division_ffi_create_drawable_text(
        division_engine::canvas::State* state,
        division_engine::canvas::RenderManager* render_manager
    )
    {
        return render_manager->create_renderer(*state, text_renderable_t {});
    }

    void
    division_ffi_destroy_entity(division_engine::canvas::State* state, uint64_t entity_id)
    {
        flecs::entity { state->world, entity_id }.destruct();
    }
}